﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Globalization;
using TSharp.Core.Mvc.Web;

namespace TSharp.Core.AppBox.Controllers
{
    /// <summary>
    /// 语言选择控制器
    /// <para>2010/10/26</para>
    /// 	<para>TANGJINGBO</para>
    /// 	<author>tangjingbo</author>
    /// </summary>
    public class SiteController : TSharpController
    {

        /// <summary>
        /// 选择一个语言
        /// </summary>
        /// <param name="theme">The theme.</param>
        /// <returns></returns>
        public ActionResult Culture()
        {
            var cp = AopContext.Default.Resolve<ISiteProvider>();
            IEnumerable<Culture> cultureConllection = cp.GetAllCultureInfo();// CultureInfo.GetCultures(CultureTypes.SpecificCultures).OrderByDescending(x => x.NativeName);
            return View(cultureConllection);

        }
        public ActionResult SetCulture(string culture, string returnUrl)
        {
            var cp = AopContext.Default.Resolve<ISiteProvider>();
            if (Request.RequestType.Equals("post", StringComparison.OrdinalIgnoreCase))
            {
                culture = Request.Form["cultureName"];
                returnUrl = Request.Form["urlcurrent"];
            }
            cp.SetCurrentCultureInfo(culture);
            return Json(null);
        }
        public ActionResult Theme()
        {
            var cp = AopContext.Default.Resolve<ISiteProvider>();
            IEnumerable<Theme> themeConllection = cp.GetAllTheme();// CultureInfo.GetCultures(CultureTypes.SpecificCultures).OrderByDescending(x => x.NativeName);
            return View(themeConllection); 
        }
        public ActionResult SetTheme(string theme, string returnUrl)
        {
            var cp = AopContext.Default.Resolve<ISiteProvider>();
            if (Request.RequestType.Equals("post", StringComparison.OrdinalIgnoreCase))
            {
                theme = Request.Form["themeName"];
                returnUrl = Request.Form["urlcurrent"];
            }
            cp.SetCurrentTheme(theme);
            return Json(null);
        }
        public ActionResult Index()
        {
            IEnumerable<CultureInfo> cultureConllection = CultureInfo.GetCultures(CultureTypes.SpecificCultures).OrderByDescending(x => x.Name);
            return View(cultureConllection);
        }
    }
}
